#include "app_runner.h"
#include "app_pool.h"
#include "app_mqtt.h"
#include "app_device.h"
#include "app_bt.h"
#include "log/log.h"
#include <signal.h>
#include <unistd.h>

static int is_running = 1;

void exit_handler(int signo)
{
    is_running = 0;
}

void app_runner_run()
{
    //注册信号处理函数
    signal(SIGINT, exit_handler);
    signal(SIGTERM, exit_handler);

    //初始化线程池
    app_pool_init(5);
    //初始化mqtt客户端
    app_mqtt_init();
    //初始化设备
    Device *device = app_device_init(DEVICE_FILE);
    //初始化蓝牙和串口
    app_bt_init(device);
    //启动设备
    app_device_start();

    while(is_running)
    {
        sleep(1);
    }

    //释放资源
    app_pool_close();
    app_mqtt_close();
    app_device_destroy();
}